package cn.hsw.platform.core.validated.valid;

import cn.hsw.platform.core.util.Validator;
import cn.hsw.platform.core.validated.annotations.MustIn;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 必须在其中验证
 * @author 李子木
 * @date 2020-11-05
 */
public class MustInValid implements ConstraintValidator<MustIn, Object> {

    private MustIn constraint;

    @Override
    public void initialize(MustIn constraint) {
        this.constraint = constraint;
    }
    @Override
    public boolean isValid(Object obj, ConstraintValidatorContext context) {

        if(Validator.isNotEmpty(obj)){
            return Validator.contains(constraint.types(),obj+"");
        }
        return false;
    }
}
